﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace AppToolkit.WPF.UI
{
    /// <summary>
    /// Properties of a <see cref="TreeViewItem"/>
    /// </summary>
    public static class TreeViewItemProps
    {
        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string GetItemImageName(DependencyObject obj)
        {
            return (string)obj.GetValue(ItemImageNameProperty);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetItemImageName(DependencyObject obj, string value)
        {
            obj.SetValue(ItemImageNameProperty, value);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool GetIsLoading(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsLoadingProperty);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetIsLoading(DependencyObject obj, bool value)
        {
            obj.SetValue(IsLoadingProperty, value);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool GetIsLoaded(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsLoadedProperty);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetIsLoaded(DependencyObject obj, bool value)
        {
            obj.SetValue(IsLoadedProperty, value);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool GetIsCanceled(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsCanceledProperty);
        }

        /// <summary>
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetIsCanceled(DependencyObject obj, bool value)
        {
            obj.SetValue(IsCanceledProperty, value);
        }

        /// <summary>
        /// Get/Set name of the image that is displayed with the <see cref="TreeViewItem"/>.
        /// </summary>
        public static readonly DependencyProperty ItemImageNameProperty;
        /// <summary>
        /// Represents the state, when the subnodes are currently loading.
        /// </summary>
        public static readonly DependencyProperty IsLoadingProperty;
        /// <summary>
        /// Represents the state when loading the subnodes was finished.
        /// </summary>
        public static readonly DependencyProperty IsLoadedProperty;
        /// <summary>
        /// Returns true, if loading of subnodes was canceled.
        /// </summary>
        public static readonly DependencyProperty IsCanceledProperty;

        static TreeViewItemProps()
        {
            ItemImageNameProperty = DependencyProperty.RegisterAttached("ItemImageName", typeof(string), typeof(TreeViewItemProps), new UIPropertyMetadata(string.Empty));

            IsLoadingProperty = DependencyProperty.RegisterAttached("IsLoading",
                                                                    typeof(bool), typeof(TreeViewItemProps),
                                                                    new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));

            IsLoadedProperty = DependencyProperty.RegisterAttached("IsLoaded",
                                                                    typeof(bool), typeof(TreeViewItemProps),
                                                                    new FrameworkPropertyMetadata(false));

            IsCanceledProperty = DependencyProperty.RegisterAttached("IsCanceled",
                                                                    typeof(bool), typeof(TreeViewItemProps),
                                                                    new FrameworkPropertyMetadata(false));
        }
    }
}
